<template>
	<view class="container">
		<view class="title">
			<view class="title1">欢迎进入金叶制冷设备</view>
			<view class="title2">登录了解更多精彩信息</view>
		</view>
		<view class="logo">
			<image src="../../static/logo.png" mode="widthFix" style="width: 200rpx;"></image>
		</view>
		<div class="logo_btn" style="padding: 0 20rpx">
			<button class="wx_btn" open-type="getUserInfo"  @click="wxLogin">
				<u-icon name="weixin-fill" size="32"></u-icon><text style="margin-left: 10upx">微信用户一键登录</text>
			</button>
		</div>
	</view>
</template>

<script>
	import request from '../../utils/http.js'
	export default {
		data() {
			return {
			};
		},
		// onLoad() {
		// 	this.wxLogin()
		// },
		methods: {
			wxLogin() {
				uni.showNavigationBarLoading()
				wx.login({
					success(res) {
						if (res.code) {
							wx.request({
								url: 'http://pengfh.com:8080/mobile/token/login',
								data: {
									mobile: 'WX@' + res.code
								},
								method: 'post',
								header: {
									'content-type': 'application/x-www-form-urlencoded',
								},
								success(res) {
									uni.setStorageSync('cookie', res.cookies[0])
									uni.switchTab({
										url: '/pages/index/index'
									})
								}
							})
							uni.hideNavigationBarLoading()
						} else {
							console.log('登录失败', res.errMsg)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wx_btn {
		color: #fff;
		background: #1F476D;
		height: 90upx;
		border-radius: 16upx;
		text-align: center;
		line-height: 90upx;
		font-size: 28upx;

		&:before,
		&:after {
			border: none;
		}
	}
	.container{
		.logo{
			text-align: center;
			margin: 40rpx 0;
		}
		.title{
			padding: 20rpx;
		}
		.title1{
			font-size: 36rpx;
			font-weight: bold;
		}
		.title2{
			font-size: 28rpx;
			color: #878787;
		}
	}
</style>
